//bases on Mark Nelson implementation of GST

package ru.osu.acm.system.sourcediff;

class Suf {
    private Uzel SameUzel;
    private int beginInd;
    private int endInd;

    public Suf(Uzel SameUzel, int beginInd, int endInd) {
        this.SameUzel = SameUzel;
        this.beginInd = beginInd;
        this.endInd = endInd;
    }

    public boolean isLR() {
        return beginInd > endInd;
    }

    public void refactor() {
        if (!isLR()) {
            Rebro Rebro = SameUzel.findRebro(SameUzel.charAt(beginInd));

            int RebroLen = Rebro.getLen();
            while (RebroLen <= getLen()) {
                beginInd += RebroLen + 1;
                SameUzel = Rebro.getEndUzel();
                if (beginInd <= endInd) {
                    Rebro = Rebro.getEndUzel().findRebro(SameUzel.charAt(beginInd));
                    RebroLen = Rebro.getLen();
                }
            }
        }
    }

    public int getLen() {
        return endInd - beginInd;
    }

    public Uzel getSameUzel() {
        return SameUzel;
    }

    public int getBeginInd() {
        return beginInd;
    }

    public void incBeginInd() {
        beginInd++;
    }

    public void changeSameUzel() {
        SameUzel = SameUzel.getSufUzel();
    }

    public void incEndInd() {
        endInd++;
    }
}
